<template>
  <div style="display: flex; margin: 20px">
    <a-input
      style="width: 200px"
      :max-length="5"
      type="number"
      placeholder="请输入新增金额"
      v-model:value="addValue"
    ></a-input>
    <a-button type="primary" style="margin-left: 20px" @click="addGold"
      >新增</a-button
    >
  </div>
  <div>
    <!-- 对话框 -->
    <a-modal v-model:visible="visible" title="修改参数" @ok="handleOk">
      <div>
        <a-input v-model:value="updateData.num" />
      </div>
    </a-modal>
    <a-table
      :columns="columns"
      :data-source="historyData"
      :loading="loading"
      :pagination="historyPagination"
      :rowKey="(record) => record.id"
      @change="historyChange"
      bordered
    >
      <template #id="id">
        <a @click="undateGold(id.record)"> 编辑 ｜ </a>
        <a-popconfirm
          placement="topRight"
          ok-text="Yes"
          cancel-text="No"
          @confirm="deleteGold(id.record.id)"
        >
          <template #title>
            <p>确定要删除吗</p>
          </template>
          <a>删除</a>
        </a-popconfirm>
      </template>
    </a-table>
  </div>
</template>

<script lang="ts">
import Vue, { defineComponent, reactive, toRefs } from "vue";
import { history } from "./hosk";
export default defineComponent({
  setup() {
    const {
      state,
      getHistory,
      change,
      historyChange,
      addGold,
      formatDate,
      deleteGold,
      undateGold,
    } = history();
    getHistory();
    return {
      columns,
      change,
      getHistory,
      historyChange,
      formatDate,
      addGold,
      deleteGold,
      undateGold,
      ...toRefs(state),
    };
  },
});
const columns = [
  {
    title: "金额",
    key: "num",
    dataIndex: "num",
    align: "center",
  },
  {
    title: "id",
    key: "编辑",
    dataIndex: "id",
    slots: { customRender: "id" },
    align: "center",
  },
];
</script>

<style lang="less" scoped>
.table {
  width: 100%;
  overflow-x: hidden;
  overflow-y: scroll;
  background-color: #121c30;
}

.head {
  display: flex;
  width: 300px;
  justify-content: space-between;
  margin-top: -30px;
  margin-bottom: 30px;

  button {
    width: 120px;
    height: 40px;
    font-size: 22px;
  }
}

.on {
  color: #40a9ff;
}

.off {
  color: rgb(47, 45, 45);
}

.col {
  color: red;
}
</style>
